package kr.co.redcircle.service.oAuth;

import java.util.Scanner;

import kr.co.redcircle.service.oAuth.api.google.Google20Api;

import org.scribe.builder.ServiceBuilder;
import org.scribe.model.OAuthRequest;
import org.scribe.model.Response;
import org.scribe.model.Token;
import org.scribe.model.Verb;
import org.scribe.model.Verifier;
import org.scribe.oauth.OAuthService;

public class YoutubeTestCase
{
	  private static final String NETWORK_NAME = "Youtube";
	  private static final String PROTECTED_RESOURCE_URL = "https://gdata.youtube.com/feeds/api/videos?q=football+-soccer&orderby=published&start-index=11&max-results=10&v=2&alt=jsonc";
	  private static final String SCOPE = "https://www.googleapis.com/auth/userinfo.profile https://www.googleapis.com/auth/userinfo.email";
	  private static final Token EMPTY_TOKEN = null; 
 
	  public static void main(String[] args)
	  {


		  String apiKey = "149480197372.apps.googleusercontent.com";
		  String apiSecret = "XFxNGiyLVdY5F0G2iFH8g2BR";
		  String callback = "http://broker.inpion.com/ExampleBizBrokerWASClient/YoutubeOAuth.jsp";
		  String scope = "https://gdata.youtube.com";
		  
		  OAuthService service = new ServiceBuilder().
	    		provider(Google20Api.class).
	    		apiKey(apiSecret).
	    		apiSecret(apiSecret).
	    		callback(callback).
	    		scope(scope).
	    		build();
	    
		  Scanner in = new Scanner(System.in);

		  String authorizationUrl = service.getAuthorizationUrl(EMPTY_TOKEN);
		  System.out.println(authorizationUrl);
		  Verifier verifier = new Verifier(in.nextLine());
	    
		  Token accessToken = service.getAccessToken(EMPTY_TOKEN, verifier);

		  OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL);
		  service.signRequest(accessToken, request);
		  Response response = request.send();
		  System.out.println(response.getCode());
		  System.out.println(response.getBody());

	}
  
}